/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package be.hogent.iii.project.guigameroom;

import java.awt.Dimension;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 *
 * @author jef donders
 */
public class LijstPanel extends JPanel implements ListSelectionListener{

    private GameRoomGui gameRoom;
    private JList lijst;
    String [] inhoud;
    
    public LijstPanel(GameRoomGui gui, Dimension size, String [] inhoud){
        this.gameRoom = gui;
        this.inhoud = inhoud;
        lijst = new JList(inhoud);
        lijst.setCellRenderer(new LijstCellRenderer("joske"));
        lijst.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        lijst.addListSelectionListener(this);
        add(lijst);
        
        
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        setLayout(layout);
        layout.setHorizontalGroup(layout.createSequentialGroup()
            .addComponent(lijst,size.width -5,size.width -5,size.width -5)
        );
        layout.setVerticalGroup(layout.createSequentialGroup()
            .addComponent(lijst,size.height-100,size.height-50 ,size.height-50)
        );
    }

    public void valueChanged(ListSelectionEvent e) {
        if (!e.getValueIsAdjusting()){
            gameRoom.setInfoPanel(inhoud[lijst.getSelectedIndex()]);
        }
    }
    
    
}
